package com.jason.basecommonlib.imagecache;

import android.content.Context;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.jason.basecommonlib.network.BaseRequestQueue;

public class ImageLoaderHelper {

    public static final String IMAGE_CACHE_DIR = "temp";

    private RequestQueue mImageQueue;
    private ImageLoader mImageLoader;
    private ImageLoader.ImageCache mImageCache;
    private static ImageLoaderHelper mInstance;

    private ImageLoaderHelper(Context context) {
        mImageQueue = BaseRequestQueue.newSpecialRequestQueue(context);
        ImageBitmapCache.ImageCacheParams cacheParams = new ImageBitmapCache.ImageCacheParams(IMAGE_CACHE_DIR);
        cacheParams.memCacheSize = 1024 * 1024 * ImageUtils.getMemoryClass(context) / 3;
        mImageCache = ImageBitmapCache.getInstanceCache(context, cacheParams);
        mImageLoader = new ImageLoader(mImageQueue, mImageCache);
    }

    public static synchronized ImageLoaderHelper getInstance(Context context) {
        if (mInstance == null) {
            mInstance = new ImageLoaderHelper(context);
        }
        return mInstance;
    }

    public ImageLoader getImageLoader() {
        return mImageLoader;
    }

    public ImageLoader.ImageCache getImageCache() {
        return mImageCache;
    }

}
